package com.qiuzhiyi.activity;

import android.widget.TextView;

import com.li.widget.TopNavigationBar;
import com.qiuzhiyi.R;
import com.qiuzhiyi.base.QZYBaseActivity;
import com.qiuzhiyi.net.ObservableHelper;
import com.qiuzhiyi.net.RetrofitHelper;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class StoreDetailActivity extends QZYBaseActivity {


    @BindView(R.id.top_navigation)
    TopNavigationBar mTopNavigation;
    @BindView(R.id.txt_name)
    TextView mTxtName;
    @BindView(R.id.txt_address)
    TextView mTxtAddress;
    @BindView(R.id.txt_info)
    TextView mTxtInfo;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_store_detail;
    }

    @Override
    protected void initSth() {
        super.initSth();
        mTopNavigation.setNavigationBarListener(this);
        getStoreDetail(getIntent().getStringExtra("sId"));
    }

    private void getStoreDetail(String sId) {
        showLoadingDialog();
        Map<String, String> map = new HashMap<>();
        map.put("sId", sId);
        ObservableHelper.createObservable(RetrofitHelper.createService().getStoreInfo(map))
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        addDisposable(d);
                    }

                    @Override
                    public void onNext(String s) {
                        dismissLoadingDialog();
                        try {
                            JSONObject object=new JSONObject(s);
                            object=object.getJSONObject("objValue");
                            mTxtName.setText(object.getString("suppcompany"));
                            mTxtAddress.setText(object.getString("suppname"));
                            mTxtInfo.setText(object.getString("remark"));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        dismissLoadingDialog();
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

}
